﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeGrid.aspx.cs" Inherits="Cms.Web.CmsSystem.SysModules.PopWin.TreeGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="/App_Themes/Default/easyui/icon.css" rel="stylesheet" type="text/css" />
    <link href="/App_Themes/Default/easyui/easyui.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/Scripts/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="/Scripts/json.js" type="text/javascript"></script>
    <script type="text/javascript">
        var listype = '<%=DialogConfig!=null?DialogConfig.Type.ToString():""%>';
        var selChild = "false";
        var unSelParent = "false";
        var isselchild = selChild.toLowerCase() == "true";
        var isUnSelParent = unSelParent.toLowerCase() == "true";
        function selectdata(rowdata, assgin) {
            if (listype == "12") {
                var queryParams = $('#treegrid').treegrid('options').queryParams;
                var v = rowdata[assgin];
                queryParams["pid"] = v;
                $("#gridlist").datagrid("options").queryParams["pid"] = v;
                $("#gridlist").datagrid('reload');
            }
            else if (listype == "2" && isselchild) {
                var idfield = $('#treegrid').treegrid('options').idField;
                var sid = rowdata[idfield];
                var cko = $("tr[node-id=" + sid + "] input[type=checkbox]");
                var ck = false;
                if (cko.size() > 0) {
                    ck = cko.attr("checked");
                    var childs = checkChild(sid, ck);
                    if (isUnSelParent && (!childs || childs.length == 0)) {
                        if (!ck) {
                            var p = $('#treegrid').treegrid('getParent', sid);
                            if (p) {
                                var idfield = $('#treegrid').treegrid('options').idField;
                                $('#treegrid').treegrid("unselect", p[idfield]);
                            }
                        }
                    }
                }
            }
        }
        function checkChild(sid, ischeck) {
            var idfield = $('#treegrid').treegrid('options').idField;
            var childs = $('#treegrid').treegrid('getChildren', sid);
            var c, cid;
            if (childs.length > 0) {
                for (var i = 0; i < childs.length; i++) {
                    c = childs[i];
                    cid = c[idfield];
                    if (ischeck)
                        $('#treegrid').treegrid("select", cid);
                    else
                        $('#treegrid').treegrid("unselect", cid);
                }
            }
            return childs;
        }
        function treeloadsuccess(row, data) {
            if (listype == "2" && isselchild) {
                $("tr[node-id] input[type=checkbox]").bind("click", function () {
                    //alert("ddddd");
                    var ck = $(this).attr("checked");
                    var id = $(this).parents("tr[node-id]").attr("node-id");
                    //选中当前子节点. 并返回子节点.
                    var childs = checkChild(id, ck);
                    if (isUnSelParent && (!childs || childs.length == 0)) {
                        if (!ck) {
                            var p = $('#treegrid').treegrid('getParent', id);
                            if (p) {
                                var idfield = $('#treegrid').treegrid('options').idField;
                                $('#treegrid').treegrid("unselect", p[idfield]);
                            }
                        }
                    }
                });
            }
        }
        function GetParent(nodeid) {
            return $('#treegrid').treegrid('getParent', nodeid);
        }
        function GetChilds(nodeid) {
            return $('#treegrid').treegrid('getChildren', nodeid);
        }
        function GetAllNodes() {
            var roots = $('#treegrid').treegrid('getRoots');
            return roots;
        }
        function ReturnOk() {
            if (listype != "") {
                var SelectRow = [];
                if (listype == "1" || listype == "12") {
                    SelectRow = $("#gridlist").datagrid("getSelections");
                }
                else {
                    SelectRow = $("#treegrid").treegrid("getSelections");
                }
                //debugger;
                return JSON.stringify(SelectRow);
            }
            else
                return "";

        }
    </script>
</head>
<body class="easyui-layout" style="padding: 0; margin: 0; position: relative;" fit="true">
    <asp:Literal ID="LitTool" runat="server"></asp:Literal>
    <asp:Literal ID="LitTreeGrid" runat="server"></asp:Literal>
    <asp:Literal ID="LitDataGrid" runat="server"></asp:Literal>
    <asp:Literal ID="LitBtnList" runat="server"></asp:Literal>
</body>
</html>
